<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<style> 
/* Z-index of #mask must lower than #boxes .window */
#mask {
  position:absolute;
  z-index:9000; top:0; left: 0;
  background-color:#000;
  display:none;
}
   
#option4-order {
  position:absolute; background: rgba(255,255,255,0.24); -moz-border-radius: 5px;
  width:620px;
  display:none;
  z-index:9999;
  padding:4px;
}
#pay-mess, .err-mess, .pay-mess {margin:0 0 20px; text-align:left;color:red}
img#loading-order {position:absolute; top:0px; right:0px;padding:3px;display:none}
#money_cost {font-weight:bold;}
span.order-title {font-size:110%; font-weight:bold;text-transform:uppercase}
</style>
<div class="middle padtop10 myclear">
	<div class="page-content">
		
		<!-- bread crumb -->
		<p id="bread-crumb">
			<a href="<?php echo base_url();?>">
				<?php echo $lang['home']?>
			</a>
			<?php echo $lang['cod_title']?>
		</p>
		<!-- end bread crumb -->
		<h3>
			<?php echo $lang['cod_title']?>
		</h3>
		<br style="clear:both;" />
		<p style="width:150px;margin-bottom:-1px;background:#ddd;padding:0 3px;">
			<b class="ver-middle marright5"><?php echo $lang['type']?>: </b>
			<select id="lstType" class="ver-middle" onchange="changeApply();">
				<option value="0" <?php echo ($type == 0 ? 'selected="selected"' : '');?>>
					<?php echo $lang['pay_cod'];?>
				</option>
				<option value="1" <?php echo ($type == 1 ? 'selected="selected"' : '');?>>
					<?php echo $lang['pay_transfer'];?>
				</option>
			</select>
		</p>
		<div style="padding:15px 8px 8px;border:1px solid #ddd;background:#fff">
			<table cellpadding="3" cellspacing="1" id="pay_cod" style="<?php echo $type == 0 ? '' : 'display:none';?>">
				<tr>
					<td>
						<b class="ver-middle marright5"><?php echo $lang['status']?>: </b>
						<select id="lstStatus" class="ver-middle">
							<option value="-1" <?php echo ($status == -1 ? 'selected="selected"' : '');?>>
								<?php echo $lang['select_all'];?>
							</option>
							<option value="0" <?php echo ($status == 0 ? 'selected="selected"' : '');?>>
								<?php echo $lang['pay_new'];?>
							</option>
							<option value="1" <?php echo ($status == 1 ? 'selected="selected"' : '');?>>
								<?php echo $lang['sale_confirm'];?>
							</option>
							<option value="2" <?php echo ($status == 2 ? 'selected="selected"' : '');?>>
								<?php echo $lang['success'];?>
							</option>
						</select>
					</td>
					<td style="padding-left:15px">
						<b class="ver-middle marright5"><?php echo $lang['provice']?>: </b>
						<select id="lstProvice" class="ver-middle" onchange="get_districts();">
							<option value="-1"><?php echo $lang['select_all'];?></option>
							<?php foreach ($lstProvice as $item){?>
							<option value="<?php echo $item->id;?>" <?php echo ($item->id == $provice ? 'selected="selected"' : '');?>>
								<?php echo $item->title;?>
							</option>
							<?php }?>
						</select>
					</td>
					<td style="padding-left:15px">
						<b class="ver-middle marright5"><?php echo $lang['district']?>: </b>
						<select id="lstDistrict" class="ver-middle" style="width:120px">
						<?php if(isset($lstDistrict)){?>
							<option value="-1"><?php echo $lang['select_all'];?></option>
							<?php foreach ($lstDistrict as $item){?>
							<option value="<?php echo $item->id;?>" <?php echo ($item->id == $distric ? 'selected="selected"' : '');?>>
								<?php echo $item->title;?>
							</option>
							<?php }?>
						<?php }?>
						</select>
					</td>
					<td style="padding-left:15px">
						<input type="button" value="<?php echo $lang['apply'];?>" onclick="changeApply();" />
					</td>
				</tr>
			</table>
			<table cellpadding="3" cellspacing="1" id="pay_transfer" style="<?php echo $type == 1 ? '' : 'display:none';?>">
				<tr>
					<td>
						<b class="ver-middle marright5"><?php echo $lang['status']?>: </b>
						<select id="lstStatus2" class="ver-middle">
							<option value="-1" <?php echo ($status == -1 ? 'selected="selected"' : '');?>>
								<?php echo $lang['select_all'];?>
							</option>
							<option value="0" <?php echo ($status == 0 ? 'selected="selected"' : '');?>>
								<?php echo $lang['pay_new'];?>
							</option>
							<option value="2" <?php echo ($status == 2 ? 'selected="selected"' : '');?>>
								<?php echo $lang['success'];?>
							</option>
						</select>
					</td>
					<td style="padding-left:15px">
						<input type="button" value="<?php echo $lang['apply'];?>" onclick="changeApply();" />
					</td>
				</tr>
			</table>
		</div>
		<br />
		<table class="tbl-list" width="100%" border="1">
			<tr>
				<td width="3%" class="td-label" style="text-align:center">
					<b>#</b>
				</td>
				<td width="12%" class="td-label">
					<b><?php echo $lang['name']?></b>
				</td>
				<td class="td-label" width="20%">
					<b><?php echo $lang['address']?></b>
				</td>
				<td class="td-label" width="16%">
					<b><?php echo $lang['note']?></b>
				</td>
				<td class="td-label" style="text-align:right">
					<b><?php echo $lang['money_ad'].' '.$lang['currency'];?></b>
				</td>
				<?php if($type == 0){?>
				<td class="td-label" style="text-align:right">
					<b><?php echo $lang['money_coll'].' '.$lang['currency'];?></b>
				</td>
				<?php }?>
				<td class="td-label">
					<b><?php echo $lang['date'];?></b>
				</td>
				<td class="td-label" style="text-align:left">
					<b><?php echo $lang['status']?></b> &nbsp;
					<img id="loading" src="/images/ajaxLoading.gif" border="0" style="display:none" />
				</td>
			</tr>
			<?php $i = 0; foreach ($items as $item){ $i++; ?>
			<tr>
				<td style="text-align:center">
					<?php echo $i;?>
				</td>
				<td>
					<p><?php echo $item->name;?></p>
					<p><?php echo $lang['user'].': '.$item->username;?></p>
				</td>
				<td>
					<?php if($type == 0){?>
					<p>
						<?php echo $item->address.', '.$item->districtname.', '.$item->provincename;?>
					</p>
					<?php }?>
					<p>
						<?php echo $lang['phone'].': '.$item->phone;?>
					</p>
					<p>
						<?php echo $lang['email'].': '.$item->email;?>
					</p>
				</td>
				<td>
					<?php echo $item->note;?>
				</td>
				<td style="text-align:right">
					<?php echo number_format($item->valueads);?>
				</td>
				<?php if($type == 0){?>
				<td style="text-align:right">
					<?php echo number_format($item->totalvalue);?>
				</td>
				<?php }?>
				<td>
					<?php echo date('d-m-Y H:i:s', strtotime($item->createdtime));?>
				</td>
				<td style="text-align:center;vertical-align:middle">
					<?php if($item->status == 2){ echo $lang['success']; }
					else {
						echo $lang['arr_type_cod'][$item->status];
					?>
					<br />
					<input type="button" value="<?php echo $lang['add_money'];?>" onclick="addMoney(<?php echo $item->id;?>,1);" />
					<?php }?>
				</td>
			</tr>
			<?php }?>
		</table>
		<!-- paging -->
			<div class="myclear martop20">
				<div class="brv-paging-left">
					<table class="tbl-list brv-paging" border="1">
						<tr>
							<td class="brv-paging-name">
								<?php echo $lang['page'].' '. $page.' ['.$pages.']'?>
							</td>
							
							<td class="brv-paging-pre-next">
								<img class="brv-img-pre" alt="previous" src="/images/imgpre.gif" onclick="goPage(<?php echo $page > 1 ? $page - 1 : $page;?>)" />
								<img class="brv-img-next" alt="next" src="/images/imgnext.gif" onclick="goPage(<?php echo $page < $pages ? $page + 1 : $page;?>)" />
							</td>
						</tr>
					</table>
				</div>
				<!-- important. fix for ie 6. Don't remove -->
				<!--[if IE 6]><br class="clearboth" /><![endif]-->
			</div>
			<!-- end paging -->
	</div>
</div><br />
<div id="popup-payment"></div>
<div id="mask"></div>
<script type="text/javascript">
function goPage(strVal)
{
	var status = $('#lstStatus').val();
	var provice = $('#lstProvice').val();
	var district = $('#lstDistrict').val();
	var type = $('#lstType').val();
	if(type == 1) status = $('#lstStatus2').val();
	if(type == 0)
		window.location = '<?php echo site_url('payment');?>/?st='+status+'&pvc='+provice+'&dst='+district+'&type='+type+'&page='+strVal;
	else
		window.location = '<?php echo site_url('payment');?>/?st='+status+'&type='+type+'&page='+strVal;
}
function changeApply()
{
	var status = $('#lstStatus').val();
	var provice = $('#lstProvice').val();
	var district = $('#lstDistrict').val();
	var type = $('#lstType').val();
	if(type == 1) status = $('#lstStatus2').val();
	if(type == 0)
		window.location = '<?php echo site_url('payment');?>/?st='+status+'&pvc='+provice+'&dst='+district+'&type='+type;
	else
		window.location = '<?php echo site_url('payment');?>/?st='+status+'&type='+type;
}
function payPopup(id) { 
	 
	id = '#' + id;
    //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
     
        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});
         
        //transition effect    
        $('#mask').fadeIn(500);   
        $('#mask').fadeTo("fast",0.8); 
     
        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
               
        //Set the popup window to center
        $(id).css('top',  winH/2-$(id).height()/2 + $(window).scrollTop());
        $(id).css('left', winW/2-$(id).width()/2);
     
        //transition effect
        $(id).fadeIn(500);

        //if mask is clicked
        $('#mask').click(function () {
            $(this).hide();
            $(id).hide();
        });
	}
function get_districts()
{
	//$('#loading-cold').show();
	var proid = $('#lstProvice').val();
	$.ajax({
		url: '<?php echo site_url('payment/districts_get_all/?id=');?>' + proid,
		success: function(data){
			//$('#loading-cold').hide();
			$('#lstDistrict').html(data);
		}
	});
}
function submitAction(obj, id)
{
	if(!confirm('<?php echo $lang['confirm_action'];?>')) return;
	var action = $(obj).val();
	$.ajax({
		type: 'post',
		data: {action:action,id:id},
		url: '<?php echo site_url('payment/updateAction');?>',
		success: function(){
			changeApply();
		}
	});
}
function selectType()
{
	var obj = $('#lstType').val();
	if(obj == 0)
	{
		$('#pay_cod').fadeIn('fast');
		$('#pay_transfer').fadeOut('fast');
	}
	else
	{
		$('#pay_transfer').fadeIn('fast');
		$('#pay_cod').fadeOut('fast');
	}
}
function addMoney(id,opt)
{
	if(opt == 1)
	{
		$('#loading').fadeIn('fast');
		$.ajax({
			url: '<?php echo site_url('payment/addMoney/?id=');?>'+id,
			success: function(data){
				$('#loading').fadeOut('fast');
				$('#popup-payment').html(data);
				payPopup('option4-order');
			}
		});
	}
	if(opt == 2)
	{
		$('#loading-order').fadeIn('fast');
		var money = $('#txtMoney').val();
		$.ajax({
			type: 'post',
			data: {money:money},
			url: '<?php echo site_url('payment/addMoney/?id=');?>'+id,
			success: function(data){
				$('#loading-order').fadeOut('fast');
				data = $.parseJSON(data);
				$('#option4-order .pay-mess').html(data.mess);
				if(data.status == 1) setTimeout("$('#mask,#option4-order').hide();changeApply();", 3000);
			}
		});
	}
}
</script>